package com.qiaofang.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.DateUtils;
import com.qiaofang.common.response.CommonResponse;
import com.qiaofang.common.response.SuccessfulResponseFactory;
import com.qiaofang.common.utils.StringUtil;
import com.qiaofang.dto.ListSmsHistoryDTO;
import com.qiaofang.dto.PremisesDTO;
import com.qiaofang.request.*;
import com.qiaofang.response.ListPremisesResponse;
import com.qiaofang.response.ListSmsHistoryResponse;
import com.qiaofang.service.PremisesService;
import com.qiaofang.service.SmsHistoryService;
import com.qiaofang.service.V10ApiService;
import com.qiaofang.vo.SmsHistoryExportVO;
import com.qiaofang.vo.SmsHistoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = {"楼盘"})
@RequestMapping(value = "/premises", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public class PremisesController {

    @Autowired
    private PremisesService premisesService;

    @Autowired
    private V10ApiService v10ApiService;

    @PostMapping(value = "/listPremises")
    @ApiOperation(value = "楼盘列表")
    public ListPremisesResponse listPremises(@RequestBody PremisesRequest request) throws ParseException {
        ListPremisesResponse response = new ListPremisesResponse();
        PremisesDTO dto = new PremisesDTO();
        dto.setCompanyName(request.getCompanyName());
        dto.setName(request.getName());
        response.setData(premisesService.listPremises(dto, request.getPage()));
        return response;
    }

    @PostMapping(value = "/deletePremises")
    @ApiOperation(value = "后台运营删除楼盘")
    public CommonResponse deletePremises(@RequestBody @Valid DeletePremisesRequest request) {

        premisesService.deletePremises(request.getId());
        v10ApiService.deletePremisesToV10(request.getId());
        return SuccessfulResponseFactory.getSuccessResponse();
    }

}
